#ifndef NETWORKMANAGER_H
#define NETWORKMANAGER_H

#include <QObject>
#include <QMutex>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>

#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>

#include <QDebug>
#include "Mid_Struct.h"

#include "online_process_list_model.h"

class NetWorkManager : public QObject
{
    Q_OBJECT

public:

    static NetWorkManager* getInstance(QObject *parent = nullptr);
    static NetWorkManager* m_Instance;
    static QMutex m_mutex;

    // 通用字符串拆分函数，从"编号,名称,值"格式中提取值
    QString extractValue(const QString& fieldStr) {
        QStringList parts = fieldStr.split(",");
        if (parts.size() >= 3) {
            return parts[2].trimmed();
        }
        return ""; // 格式不符时返回空字符串
    }



    void processCudata_ChangFeng(const QJsonObject &originalData);

    void processCudata_XinGeEr(const QJsonObject &originalData);

    void processCutData_SuZhi(const QJsonObject &originalData);

    void processCudata_ChuangPin(const QJsonObject &originalData);

signals:

    void send_NetWork_ChangFeng_Url(QString URL);
    void send_NetWork_XinGeEr_Url(QString URL);
    void send_NetWork_SuZhi_Url(QString URL);
    void send_NetWork_ChuangPin_Url(QString URL);

    void send_UpData_ListView_Signal(const QVector<cutData> &data);

public slots:

    void recv_Scanner_Result_ChangFeng_Slots(const QByteArray &result);

    void recv_Scanner_Result_XinGeEr_Slots(const QByteArray &result);

    void recv_Scanner_Result_SuZhi_Slots(const QByteArray &result);

    void recv_Scanner_Result_ChuangPin_Slots(const QByteArray &result);


    void recv_NetWork_ChangFeng_Process_List_Slots(QString URL);

    void recv_NetWork_XinGeEr_Process_List_Slots(QString URL);

    void recv_NetWork_SuZhi_Process_List_Slots(QString URL);

    void recv_NetWork_ChuangPin_Process_List_Slots(QString URL);

private:
    NetWorkManager(QObject *parent = nullptr);
    ~NetWorkManager();
    NetWorkManager(const NetWorkManager&) = delete;
    NetWorkManager& operator=(const NetWorkManager) = delete;

    QNetworkAccessManager* m_NetWorkManager = nullptr;

    QVector<cutData> aggregatedData;

    Online_Process_List_Model* model = nullptr;


};

#endif // NETWORKMANAGER_H
